package com.example.myapplication;

import com.example.myapplication.shortvideo.utils.GsonUtil;

import org.jetbrains.annotations.NotNull;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;

/**
 * @author: rongfeng
 * @date: 2020/12/15
 * @description
 */
public class DowdLoadImg3 {

    public static void main(String[] args) {
        new Query().getDns();
    }


    public static class Query {
        List<DowdLoadImg2.DataList> urlList = new ArrayList<>();
        public void getDns() {
            File file = new File("C:\\Users\\demo\\Desktop\\json.txt");
            try {
                String str;
                FileInputStream fileInputStream = new FileInputStream(file);
                InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream);
                BufferedReader bufferedReader = new BufferedReader(inputStreamReader);

                StringBuffer sb = new StringBuffer();
                String text = null;
                while ((text = bufferedReader.readLine()) != null) {
                    sb.append(text);
                }
                str = sb.toString();

                Bean.Root bean = GsonUtil.parse(str, Bean.Root.class);
                for (Bean.ImageList avatar : bean.getImageList()) {
                    urlList.add(new DowdLoadImg2.DataList(avatar.imageUrl));
                }

                new DowdLoadImg2().addList(urlList);
            } catch (Exception e) {
                e.printStackTrace();
            }

        }


        public static class Bean {
            public class ImageList
            {
                private String imageUrl;

                public void setImageUrl(String imageUrl){
                    this.imageUrl = imageUrl;
                }
                public String getImageUrl(){
                    return this.imageUrl;
                }
            }
            public class Root
            {
                private String type;

                private String imageIcon;

                private List<ImageList> imageList;

                public void setType(String type){
                    this.type = type;
                }
                public String getType(){
                    return this.type;
                }
                public void setImageIcon(String imageIcon){
                    this.imageIcon = imageIcon;
                }
                public String getImageIcon(){
                    return this.imageIcon;
                }
                public void setImageList(List<ImageList> imageList){
                    this.imageList = imageList;
                }
                public List<ImageList> getImageList(){
                    return this.imageList;
                }
            }


        }
    }
}
